package com.forlove.app.qselect.login.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.forlove.app.R;

/**
 * 选择照片方式
 * Created by yjl on 2017/10/23.
 */

public class ChoicePictureDialog extends Dialog {
    private View rootView;
    private Window mWindow;
    private Context mContext;
    private TextView text_choice_from_camera;
    private TextView text_choice_from_gallery;
    private TextView bt_cancel;

    public ChoicePictureDialog(Context context) {
        super(context, R.style.ShareDialogStyle);
        rootView = getLayoutInflater().inflate(R.layout.dialog_choice_picture, null);
        setContentView(rootView);
        mContext = context;
        initDialog();
        text_choice_from_camera = rootView.findViewById(R.id.text_choice_from_camera);
        text_choice_from_gallery = rootView.findViewById(R.id.text_choice_from_gallery);
        bt_cancel = rootView.findViewById(R.id.bt_cancel);
        bt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void initDialog() {
        mWindow = getWindow();
        WindowManager.LayoutParams params = mWindow.getAttributes();
        params.gravity = Gravity.BOTTOM | Gravity.CENTER;
        WindowManager windowManager = mWindow.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        params.width = (int) (display.getWidth());
        mWindow.setAttributes(params);
    }

    /**
     * 相册选取照片
     *
     * @param onClickListener
     */
    public void choiceGallertPictire(View.OnClickListener onClickListener) {
        text_choice_from_gallery.setOnClickListener(onClickListener);
    }

    /**
     * 拍照
     *
     * @param onClickListener
     */
    public void choiceCameraPicture(View.OnClickListener onClickListener) {
        text_choice_from_camera.setOnClickListener(onClickListener);
    }

}
